package com.fhz.shop;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.fhz.shop.databinding.ActivityMainBinding;
import com.fhz.shop.databinding.ActivityNavBinding;

import java.security.Permission;

import dagger.hilt.android.AndroidEntryPoint;

/**
 * 欢迎页
 */
@AndroidEntryPoint
public class MainActivity extends AppCompatActivity {


    //1,handler
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

        }
    };

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding inflate = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(inflate.getRoot());


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{
                    Manifest.permission.CAMERA,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_EXTERNAL_STORAGE
            },999);
        }

//        mHandler.sendEmptyMessageDelayed(1,3000);
        //2.down



        NavActivity.launch(MainActivity.this);
//        new CountDownTimer(5000, 1000) {
//            @Override
//            public void onTick(long millisUntilFinished) {
//                System.out.println(millisUntilFinished / 1000);
//                inflate.mainDownTime.setText(String.valueOf(millisUntilFinished/1000).concat("秒"));
//
//            }
//
//            @Override
//            public void onFinish() {
//                Log.i(TAG, "onFinish: ");
//                NavActivity.launch(MainActivity.this);
//            }
//        }.start();


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacksAndMessages(null);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if(requestCode == 999 && grantResults[0] == 0){
            System.out.println("同意");
        }
    }
}